//
//  LZRushCouponDetailRulesOfUseCell.m
//  LzzizDemo
//
//  Created by xbnzd on 16/11/7.
//  Copyright © 2016年 xbnzd. All rights reserved.
//

#import "LZFightGroupDetailRulesOfUseCell.h"
#import "GiftListLabel.h"

@interface LZFightGroupDetailRulesOfUseCell()


/**
 使用注意事项
 */
@property (weak, nonatomic) IBOutlet GiftListLabel *rulesLabel;

@property (weak, nonatomic) IBOutlet GiftListLabel *grouponNameLabel;

@property (weak, nonatomic) IBOutlet GiftListLabel *rulesContentLabel;

@property (weak, nonatomic) IBOutlet UILabel *expirationTitleLabel;

@property (weak, nonatomic) IBOutlet UILabel *expirationTimeLabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rulesToCellTitleTopConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rulesToGrouponNameTopConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *expirationTitleLabelToGrouponNameLabelTopCST;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *expirationTitleLabelToRulesContentLabelTopCST;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *expirationTitleLabelToCellTitleLabelTopCST;
@end

@implementation LZFightGroupDetailRulesOfUseCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;

    [self configureLabel];
    // Initialization code
    self.rulesLabel.text = LZLocalizedString(@"group_terms_of_use", nil);
    self.expirationTitleLabel.text = LZLocalizedString(@"mine_coupons_expiration_date", nil);
    self.grouponNameLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
    self.rulesContentLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
}


- (void)loatGrouponName:(NSString *)grouponName RulesContent:(NSString *)rulesContent ExpirationTime:(NSString *)expirationTime
{
    if (grouponName.length == 0 && rulesContent.length == 0) {
        self.expirationTitleLabelToCellTitleLabelTopCST.priority = 999;
        self.expirationTitleLabelToRulesContentLabelTopCST.priority = 250;
        self.expirationTitleLabelToGrouponNameLabelTopCST.priority = 250;
    }else{
        self.expirationTitleLabelToCellTitleLabelTopCST.priority = 250;
        self.expirationTitleLabelToRulesContentLabelTopCST.priority = 999;
        self.expirationTitleLabelToGrouponNameLabelTopCST.priority = 250;
        [self setGrouponNameLabelText:grouponName];
        [self setRulesContentLabelText:rulesContent];
    }
    
    self.expirationTimeLabel.text = expirationTime;
}


- (void)setRulesContentLabelText:(NSString *)text
{
    if (text.length == 0) {
        self.expirationTitleLabelToGrouponNameLabelTopCST.priority = 999;
        self.expirationTitleLabelToRulesContentLabelTopCST.priority = 250;
    }else {
        self.expirationTitleLabelToGrouponNameLabelTopCST.priority = 250;
        self.expirationTitleLabelToRulesContentLabelTopCST.priority = 999;
        extern CGFloat textLineSpace;
        NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
        NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
        
        [style setLineSpacing:textLineSpace];
        [style setLineBreakMode:NSLineBreakByWordWrapping];
        [style setAlignment:NSTextAlignmentLeft];
        
        [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, attStr.length)];
        self.rulesContentLabel.attributedText = attStr;
    }
   
}

- (void)setGrouponNameLabelText:(NSString *)text
{
    if (text.length == 0) {
        self.rulesToCellTitleTopConstraint.priority = 999;
        self.rulesToGrouponNameTopConstraint.priority = 250;
    }else {
        self.rulesToCellTitleTopConstraint.priority = 250;
        self.rulesToGrouponNameTopConstraint.priority = 999;
        
        extern CGFloat textLineSpace;
        NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
        NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
        
        [style setLineSpacing:textLineSpace];
        [style setLineBreakMode:NSLineBreakByWordWrapping];
        [style setAlignment:NSTextAlignmentLeft];
        
        [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, attStr.length)];
        self.grouponNameLabel.attributedText = attStr;
    }
}

#pragma mark -
#pragma mark action
- (void)configureLabel
{
    [self.rulesContentLabel setVerticalAlignment:VerticalAlignmentTop];
    [self.grouponNameLabel setVerticalAlignment:VerticalAlignmentTop];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
